//
//  AuctionCell.m
//  phmall
//
//  Created by admin on 2017/11/23.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "AuctionCell.h"

@implementation AuctionCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+ (instancetype)theShareCellWithTableView:(UITableView *)tableView{
    
    static NSString *ID = @"SetCell";
    AuctionCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[AuctionCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
    }
    return cell;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.contentView.backgroundColor=[UIColor whiteColor];
        self.goodsImage=[UIImageView new];
        self.goodsImage.image=[UIImage imageNamed:@"图片"];
        self.goodsImage.contentMode=UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:self.goodsImage];
        
        self.name=[UILabel new];
        self.name.text=@"意大利进口奶油香味蛋卷级系列250g精装多款式可选";
        self.name.font=[UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.name];
        
        self.type=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.type setTitleColor:[UIColor colorWithHexString:@"#00a0e9"] forState:UIControlStateNormal];
        [self.type setTitle:@"未开始" forState:UIControlStateNormal];
        ViewBorderRadius(self.type, 5, 1, [UIColor colorWithHexString:@"#00a0e9"]);
        self.type.titleLabel.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.type];
      
        self.bid=[UILabel new];
        self.bid.text=[NSString stringWithFormat:@"%@:",Localized(@"当前出价")];
        self.bid.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.bid];
        
        self.bidPrice=[UILabel new];
        self.bidPrice.text=@"₱99999";
        self.bidPrice.textColor=[UIColor orangeColor];
        self.bidPrice.font=[UIFont systemFontOfSize:17];
        [self.contentView addSubview:self.bidPrice];
        
        self.fixed=[UILabel new];
        self.fixed.text=[NSString stringWithFormat:@"%@:",Localized(@"一口价")];
        self.fixed.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.fixed];
        
        self.fixedPrice=[UILabel new];
        self.fixedPrice.text=@"₱99999";
        self.fixedPrice.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.fixedPrice];
        
        self.time=[UILabel new];
        self.time.text=@"距离开始:3天06小时20分23秒";
        self.time.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.time];
        
        self.line=[UILabel new];
        self.line.backgroundColor=[UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.00f];
        [self.contentView addSubview:self.line];
    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    [self.goodsImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(5);
        make.bottom.offset(-5);
        make.width.equalTo(self.goodsImage.mas_height);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.goodsImage).with.offset(10);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(5);
        make.right.equalTo(self.contentView).with.offset(-80);
    }];
    
    [self.type mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-10);
        make.width.offset(60);
        make.height.offset(25);
        make.centerY.equalTo(self.name);
    }];
    
    [self.bid mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.name.mas_bottom).with.offset(5);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(5);
    }];
    
    [self.bidPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.bid);
        make.left.equalTo(self.bid.mas_right).with.offset(5);
    }];
    
    [self.fixed mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bid.mas_bottom).with.offset(5);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(5);
    }];
    
    [self.fixedPrice mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bid.mas_bottom).with.offset(5);
        make.left.equalTo(self.fixed.mas_right).with.offset(5);
    }];
    
    
    [self.time mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.fixed.mas_bottom).with.offset(5);
        make.left.equalTo(self.goodsImage.mas_right).with.offset(5);
    }];
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView);
        make.left.equalTo(self.contentView);
        make.right.equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}
-(void)setModel:(AuctionModel *)model{
    self.name.text=model.goods_name;
    self.bidPrice.text=[NSString stringWithFormat:@"₱%@",model.start_price];
    self.fixedPrice.text=[NSString stringWithFormat:@"₱%@",model.end_price];
    [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@union/%@",IMGURL,model.goods_file1]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    if ([model.goods_status isEqualToString:@"2"]) {
        self.time.text=Localized(@"已结束");
//        [self.type setTitleColor:[UIColor colorWithHexString:@"#00a0e9"] forState:UIControlStateNormal];
        [self.type setTitle:Localized(@"已结束") forState:UIControlStateNormal];
    }
    if ([model.goods_status isEqualToString:@"1"]) {
        self.time.text=[NSString stringWithFormat:@"%@:%@",Localized(@"结束时间"),[PublicClass timeWithTimeIntervalString:model.end_price]];
//        [self.type setTitleColor:[UIColor colorWithHexString:@"#00a0e9"] forState:UIControlStateNormal];
        [self.type setTitle:Localized(@"已开始") forState:UIControlStateNormal];
    }
    if ([model.goods_status isEqualToString:@"0"]) {
        self.time.text=[NSString stringWithFormat:@"%@:%@",Localized(@"开始时间"),[PublicClass timeWithTimeIntervalString:model.start_date]];
        [self.type setTitleColor:[UIColor colorWithHexString:@"#00a0e9"] forState:UIControlStateNormal];
        [self.type setTitle:Localized(@"未开始") forState:UIControlStateNormal];
    }
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
